home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 328 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.6 KB  |  91 lines

  1. Path: engnews1.Eng.Sun.COM!train7!clamage
  2. From: jcoffin@rmii.com (Jerry Coffin)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Are all Windows programs ill-formed?
  5. Date: 6 Feb 1996 19:36:34 GMT
  6. Organization: TAEUS
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4f8a3a$sgq@natasha.rmii.com>
  9. References: <AE5J83na99@qsar.chem.msu.su> <9602010236.26117@mulga.cs.mu.OZ.AU> <9602021032.AA05302@lts.sel.alcatel.de> <4eucsq$qn@athena.ulaval.ca>
  10. NNTP-Posting-Host: train7.eng.sun.com
  11. Content-Type: text
  12. X-Nntp-Posting-Host: slip22157.rmii.com
  13. X-Newsreader: Forte Free Agent 1.0.82
  14. Content-Length: 2847
  15. X-Lines: 68
  16. Originator: clamage@train7
  17.  
  18. Claude Quezel <Claude.Quezel@gci.ulaval.ca> wrote:
  19.  
  20. >Could window's main be simply like this:
  21.  
  22. >int main(int argc, char *argv[]) {
  23. >     // do some stuff
  24. >     return WinMain(// stuff here);
  25. >}
  26.  
  27. No.  This doesn't seem to accomplish anything.  First of all, it still
  28. requires that the user's code have WinMain defined, which is exactly
  29. what was being avoided to start with.  In addition, at least without
  30. changes in the startup code, you can define main anyway you want to, and
  31. it'll make no difference at all because it'll never get called.  If you
  32. wanted to allow code that used main to compile, you could add something
  33. like the following to the standard library:
  34.  
  35. extern int __argc;
  36. extern char *__argv[];
  37.  
  38. int WinMain(/* arguments WinMain receives */) {
  39.     return main(__argc, __argv);
  40. }
  41.  
  42. However, this really won't buy you much WRT most Windows programs: the
  43. basic structure of a normal Windows program, the header it includes, the
  44. functions it needs to use, etc., prevent the normal Windows environment
  45. from being a legal hosted implementation.  (E.g. stdin/stdout/stderr are
  46. missing...)  OTOH, if we simply view a Windows program as running in a
  47. freestanding environment, I don't see any obvious violations of the
  48. standard, even though it's highly doubtful that this is what the
  49. committee had in mind when they included freestanding implementions in
  50. the standard.
  51.  
  52. IMO, a reasonable solution to the situation would be a bit of
  53. modification in both Windows and the standard.  IMO, a slightly more
  54. restrictive version of Jonathon De Boyne Pollard's proposal might work
  55. best: require that any form of main the takes arguments have argc and
  56. argv as the first two (with whatever names the programmer desires of
  57. course) with other, implementation defined arguments allowed aftewards.
  58. In this case, a suitable version for a Win32 program might be:
  59.  
  60. int main(int argc, char **argv, HINSTANCE hInst, int nCmdShow)
  61.  
  62. By requiring that argc/argv always be passed as the first to parameters,
  63. conforming programs that expect those as the first two parameters are
  64. supported in the extended environments, whether Windows or otherwise.
  65. In this case, the entry point for a Win32 program might be:
  66.  
  67. #include <windows.h>
  68. extern int __argc;
  69. extern char *__argv[];
  70.  
  71. WinMain(HINSTANCE Inst, HINSTANCE PrevInst, char *CmdLine, int nCmdShow)
  72. {
  73. // under Win32, hPrevInst is included only for compatibility: it will
  74. // alway be NULL, so we'll ignore it.  Likewise, since we're passing
  75. // argc/argv, there's little reason to worry about the unprocessed
  76. // command line.
  77.  
  78.     return main(__argc, __argv, Inst, nCmdShow);
  79. }
  80.  
  81. This would, of course, require that main be called in such a way that if
  82. some arguments were ignored that it wouldn't cause a catastrophe.  Given
  83. the current requirement that main be able to ignore argc and argv, this
  84. shouldn't require anything new.
  85.  
  86.  
  87. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  88.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  89.   summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  90. ]
  91.